home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / PCI Driver Development Kit / • Tools / Utility / LogLibrary 950622 / Src / LogConvertTimestamp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-20  |  3.2 KB  |  102 lines  |  [TEXT/MMCC]

  1. /*                                LogConvertTimestamp.c                                */
  2. /*
  3.  * LogConvertTimestamp.c
  4.  * Copyright © 1992-95 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * This function cannot be included in the LogLibrary as it calls a MacOS "toolbox"
  7.  * function. It can be called from a 68000 application. Note that it requires the
  8.  * 64-bit math library.
  9.  *
  10.  * Edit History
  11.  */
  12. #include "LogLibrary.h"
  13.  
  14. void                        Add64(
  15.         register const UnsignedWide    *aPtr,
  16.         register const UnsignedWide    *bPtr,
  17.         register UnsignedWide        *result
  18.     );
  19. void                        Subtract64(
  20.         register const UnsignedWide    *aPtr,
  21.         register const UnsignedWide    *bPtr,
  22.         register UnsignedWide        *result
  23.     );
  24. void                        Multiply64(
  25.         const UnsignedWide        *multiplicand,    /* Multiplier * multiplicand        */
  26.         UInt32                    multiplier,        /* yields result                    */
  27.         UnsignedWide            *resultPtr
  28.     );
  29. void                        Divide64(
  30.         UnsignedWide            *dividendPtr,    /* Dividend, becomes remainder        */
  31.         const UnsignedWide        *divisorPtr,    /* Divisor, unchanged                */
  32.         UnsignedWide            *quotientPtr    /* Quotient, result                    */
  33.     );
  34.  
  35. /*
  36.  * This routine converts the event time (in AbsoluteTime units) to civil time
  37.  * (year, month, day, hour, minute, second) with nanosecond resolution. Since the
  38.  * relationship between civil time and 
  39.  *
  40.  * This function calls a Mac Toolbox routine and, hence, cannot be used (legitimately)
  41.  * by PCI device drivers.
  42.  */
  43. pascal void
  44. LogConvertTimestamp(
  45.         const LogEntryPtr        logEntryPtr,
  46.         DateTimeRec                *eventDateTime,
  47.         UInt32                    *residualNanoseconds
  48.     )
  49. {
  50.         Nanoseconds                eventNanoseconds;
  51.         UnsignedWide            eventSeconds;
  52.         UnsignedWide            temp;
  53.         static const UnsignedWide kTenE9 = { 0, 1000000000L };
  54.         static UInt32            gUpTimeNumerator;
  55.         static UnsignedWide        gUpTimeDenominator;
  56.         static Nanoseconds        gNanosecondsAtStart = { 0, 0};
  57.  
  58.         if (gNanosecondsAtStart.lo == 0 && gNanosecondsAtStart.hi == 0) {
  59.             UnsignedWide        secondsAtStart;
  60.             AbsoluteTime        absoluteTimeAtStart;
  61.             Nanoseconds            upTimeAtStart;
  62.             Nanoseconds            nanosecondsAtStart;
  63.  
  64.             GetDateTime(&secondsAtStart.lo);
  65.             LogUpTime(&absoluteTimeAtStart);
  66.             LogGetTimeBaseInfo(&gUpTimeNumerator, &gUpTimeDenominator.lo);
  67.             /*
  68.              * upTimeAtStart = AbsoluteToNanoseconds(UpTime())
  69.              */
  70.             Multiply64(&absoluteTimeAtStart, gUpTimeNumerator, &temp);
  71.             Divide64(&temp, &gUpTimeDenominator, &upTimeAtStart);
  72.             /*
  73.              * Convert the system epoch to nanoseconds.
  74.              */
  75.             secondsAtStart.hi = 0;
  76.             Multiply64(&secondsAtStart, kTenE9.lo, &nanosecondsAtStart);
  77.             /*
  78.              * Compute the offset between an UpTime value and system time of day
  79.              */
  80.             Subtract64(&nanosecondsAtStart, &upTimeAtStart, &gNanosecondsAtStart);
  81.         }
  82.         /*
  83.          * eventNanoseconds = AbsoluteToNanoseconds(eventTime)
  84.          *                     (eventTime * upTimeNumerator) / upTimeDenominator;
  85.          */
  86.         Multiply64(&logEntryPtr->eventTime, gUpTimeNumerator, &temp);
  87.         Divide64(&temp, &gUpTimeDenominator, &eventNanoseconds);
  88.         /*
  89.          * eventNanoseconds += upTimeAtStart (giving civil time at start)
  90.          */
  91.         Add64(&gNanosecondsAtStart, &eventNanoseconds, &eventNanoseconds);
  92.         /*
  93.          * eventSeconds = eventNanoseconds /= 10e9;
  94.          * residualNanoseconds = eventNanoseconds % 10e9;
  95.          */
  96.         Divide64(&eventNanoseconds, &kTenE9, &eventSeconds);
  97.         *residualNanoseconds = eventNanoseconds.lo;        /* Remainder < 10e9                */
  98.         SecondsToDate(eventSeconds.lo, eventDateTime);
  99. }
  100.  
  101.  
  102.